﻿@model VendorModel

@using Nop.Core
@using Nop.Core.Domain.Seo
@using Nop.Core.Domain.Vendors

@inject IWebHelper webHelper
@inject SeoSettings seoSettings

@{
    Layout = "_ColumnsTwo";

    //title
    NopHtml.AddTitleParts(!string.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : Model.Name);
    //meta
    NopHtml.AddMetaDescriptionParts(Model.MetaDescription);
    NopHtml.AddMetaKeywordParts(Model.MetaKeywords);
    //page class
    NopHtml.AppendPageCssClassParts("html-vendor-page");

    if (seoSettings.CanonicalUrlsEnabled)
    {
        var vendorUrl = Url.RouteUrl<Vendor>(new { SeName = Model.SeName }, webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
        NopHtml.AddCanonicalUrlParts(vendorUrl, seoSettings.QueryStringInCanonicalUrlsEnabled);
    }
}

@section CatalogFilters {
    @await Html.PartialAsync("_CatalogFilters", Model.CatalogProductsModel)
}

<div class="page vendor-page">
    <div class="page-title">
        <h1>@Model.Name</h1>
    </div>
    <div class="page-body">
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.VendorDetailsTop, additionalData = Model })
        @*description*@
        @if (!string.IsNullOrWhiteSpace(Model.Description))
        {
            <div class="vendor-description">
                @Html.Raw(Model.Description)
            </div>
        }
        @*contact vendor*@
        @if (Model.AllowCustomersToContactVendors)
        {
            <div class="contact-vendor">
                <button type="button" class="button-2 contact-vendor-button" onclick="setLocation('@Url.RouteUrl("ContactVendor", new { vendorId = Model.Id })')">@T("ContactVendor")</button>

                @if(Model.PmCustomerId > 0)
                {
                    <button type="button" class="button-2 pm-vendor-button" onclick="setLocation('@Url.RouteUrl("SendPM", new { toCustomerId = Model.PmCustomerId })')">@T("SendPmToVendor")</button>
                }
            </div>
        }
        @await Html.PartialAsync("_CatalogSelectors", Model.CatalogProductsModel)
        @{
            var catalogProductsViewData = new ViewDataDictionary(ViewData)
            {
                ["fetchUrl"] = Html.Raw(Url.RouteUrl("GetVendorProducts", new { vendorId = Model.Id }))
            };
        }
        @await Html.PartialAsync("_CatalogProducts", Model.CatalogProductsModel, catalogProductsViewData)
        
        @await Html.PartialAsync("_VendorProductReviews", Model.ProductReviews.Reviews)

        @if (Model.ProductReviews.PagingFilteringContext.TotalPages > 1)
        {
            <div class="block">
                <a href="@Url.RouteUrl("VendorReviews", new { vendorId = Model.Id })">@T("Vendors.Reviews.All")</a>
            </div>
        }

        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.VendorDetailsBottom, additionalData = Model })
    </div>
</div>
